from knowledge_base_fetcher import knowledge_base_fetcher

class mediator_fake :
    def __init__ ( self ) :
        self . _fetcher = None
        self . _received_knowledge_bases = [ ]
        self . _knowledge_bases = None
        self . _knowledge_bases_stats = { }
    def receive_knowledge_base ( self , name , creation_time , modification_time , size ) :
        self . _received_knowledge_bases += [
            [ name
            , creation_time
            , modification_time
            , size
            ] ]
    def list_knowledge_bases_request ( self ) :
        self . _fetcher . list_knowledge_bases_reply ( self . _knowledge_bases )
    def knowledge_base_creation_time_request ( self , name ) :
        self . _fetcher . knowledge_base_creation_time_reply ( self . _knowledge_bases_stats [ name ] [ 'creation_time' ] )
    def knowledge_base_modification_time_request ( self , name ) :
        self . _fetcher . knowledge_base_modification_time_reply ( self . _knowledge_bases_stats [ name ] [ 'modification_time' ] )
    def knowledge_base_size_request ( self , name ) :
        self . _fetcher . knowledge_base_size_reply ( self . _knowledge_bases_stats [ name ] [ 'size' ] )

class knowledge_base_fetcher_tests :
    'knowledge_base_fetcher'
    def __init__ ( self , test ) :
        self . _test = test
        self . _mediator = mediator_fake ( )
        self . _fetcher = knowledge_base_fetcher ( self . _mediator )
        self . _mediator . _fetcher = self . _fetcher
    def test_fetch_all_knowledge_bases ( self ) :
        self . _mediator . _knowledge_bases = [ 'my first base' , 'my second base' ]
        self . _mediator . _knowledge_bases_stats = \
            { 'my first base' : 
                { 'creation_time' : 'my first creation time'
                , 'modification_time' : 'my first modification time'
                , 'size' : 'my first size'
                }
            , 'my second base' :
                { 'creation_time' : 'my second creation time'
                , 'modification_time' : 'my second modification time'
                , 'size' : 'my second size'
                } 
            }
        self . _fetcher . fetch_all_knowledge_bases ( )
        self . _test . assume_equal ( self . _mediator . _received_knowledge_bases ,
            [ [ 'my first base'
              , 'my first creation time'
              , 'my first modification time'
              , 'my first size'
              ]
            , [ 'my second base'
              , 'my second creation time'
              , 'my second modification time'
              , 'my second size'
              ]
            ] )
